(display "\n========================================\n")
(define (element-of-set x set)
    (cond   ((null? set) #f)
            ((= x (car set)) #t)
            ((< x (car set)) #f)
            ((> x (car set))
                (element-of-set x (cdr set)))))

(define (adjoin-set x set)
    (if (null? set)
        (list x)
        (let ((current-element (car set))
              (remain-element (cdr set)))
            (cond   ((= x current-element) set)
                    ((< x current-element)
                        (cons x set))
                    ((> x current-element)
                        (cons current-element
                              (adjoin-set x remain-element)))))))
; (display (adjoin-set 10 (list 1 2 3 11)))

(define (union-set set1 set2)
    (cond   ((null? set1) set2)
            ((null? set2) set1)
            ((= (car set1) (car set2))
                (cons (car set1)
                      (union-set (cdr set1) (cdr set2))))
            ((< (car set1) (car set2))
                (cons (car set1)
                      (union-set (cdr set1) set2)))
            ((> (car set1) (car set2))
                (cons (car set2)
                      (union-set set1 (cdr set2))))))

(define (union-set set1 set2)
    (cond ((and (null? set1) (null? set2)) '())
          ((null? set1) set2)
          ((null? set2) set1)
          (else
            (let ((x1 (car set1)) (x2 (car set2)))
                (cond   ((= x1 x2)
                            (cons x1 (union-set (cdr set1) (cdr set2))))
                        ((< x1 x2)
                            (cons x1 (union-set (cdr set1) set2)))
                        ((> x1 x2)
                            (cons x2 (union-set set1 (cdr set2)))))))))

(display (union-set (list 1 2 3 4 9) (list 0 4 5 6)))


(display "\n========================================\n")
